import remen from '@/api/remen'

const state = {
  all: []
}

const actions = {
  addToCart ({commit}, remens) {
    commit('add_to_cart', remens.id)
  },
  getAllRemens ({commit}) {
    remen.getRemens(remens => {
      commit('receive_remens', remens)
    })
  }
}

const mutations = {
  receive_remens (state, remens) {
    state.all = remens
  },
  add_to_cart (state, remensId) {
    state.all.find(p => p.id === remensId).inventory--
  }
}
const getters = {
  allRemens (state) {
    return state.all
  }
}
export default {
  state,
  actions,
  mutations,
  getters
}
